class Solution {
    public void rotate(int[] nums, int k) {
        k = k % nums.length;
        stringReverse(nums,0,nums.length-k-1);
        stringReverse(nums,nums.length-k,nums.length - 1);
        stringReverse(nums,0,nums.length-1);
    }

    public static void stringReverse(int[] arr,int left,int right) {
        while (left <= right) {
            int tem = arr[left];
            arr[left] = arr[right];
            arr[right] = tem;
            left++;
            right--;
        }
    }


    // public void rotate(int[] nums, int k) {
    //     arrayReverse(nums,k);
    // }

    // public static void arrayReverse(int[] arr,int k) {
    //     int time = k % arr.length;    //旋转次数
    //     for(int i = 0; i < time; i++) {
    //         int tem = arr[arr.length - 1];
    //         int j = arr.length - 1;
    //         for(;j > 0; j--) {
    //             arr[j] = arr[j - 1];
    //         }
    //         arr[j] = tem;
    //     }
    // }



}